<template >
    <div>
        <el-table :data="menulist" border style="width: 100%" row-key="id" lazy :tree-props="{ children: 'children' }">
            <el-table-column prop="id" label="菜单编号" width="100" />
            <el-table-column prop="title" label="菜单名称" width="180" />
            <el-table-column prop="pid" label="上级菜单" width="180" />
            <el-table-column label="菜单图标" width="180">
                <template #default="item">
                    <el-icon :size="20">
                        <!-- <el-icon :class=""></el-icon> -->
                        <component :is="item.row.icon"></component>
                    </el-icon>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址" width="180" />
            <el-table-column prop="status" label="状态" width="180">
                <template #default="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
                        <el-tag v-else type="danger">禁用</el-tag>
                    </div>
                </template>

            </el-table-column>
            <el-table-column label="操作">
                <template #default="item">
                    <div>
                        <el-button type="primary" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script lang="ts" setup>
// 引入封装好的接口
import { ElMessage, ElMessageBox } from 'element-plus'
import { getMenudelete } from '../../request/api'
import { defineEmits, computed } from 'vue'
// 引入仓库方法
import { useStore } from 'vuex';
const store = useStore();
// 获取列表
const menulist = computed(() => store.getters["menu/getMenu"])
console.log(menulist, 'menulist')
const getMenu = () => {
    store.dispatch("menu/getMenuAction")
}
// 组件一加载触发行动
getMenu();
const emit = defineEmits(['edit'])
const edit = (id: any) => {
    emit('edit', id)
}


// 封装一个删除事件   
let del = (id: any) => {
    ElMessageBox.confirm(
        '你确定要删除这条信息吗?',

        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            getMenudelete({ id }).then(res => {
                console.log(res, '删除')
                if (res.code == 200) {
                    ElMessage.success(res.msg);
                    getMenu()
                } else {
                    ElMessage.error(res.msg)
                }
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消删除',
            })
        })
}
</script>
<style lang="">
    
</style>